﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BDCS.BLL;
using BDCS.Model;

namespace BDCS.UI
{
    public partial class AddSubBuildDcriterionContents : Form
    {
        private BDCS.BLL.T_SubBuildTyppes bllSubBuildType;
        private BDCS.BLL.T_BuildTyppes bllBuildType;
        private BDCS.BLL.T_BuildDesignDcriterionTypes bllBuildDesignDcriterionType;
        private BDCS.BLL.T_BuildDesignDcriterionSubTypes bllBuildDesignDcriterionSubType;
        private DataSet dataSet;
        private int btid;
        private int sbtid;
        private int dtid;
        private int dstid;
        int index;
        public AddSubBuildDcriterionContents()
        {
            InitializeComponent();
        }
        private void AddSubBuildDcriterionContents_Load(object sender, EventArgs e)
        {
            CmbBuildTypeDataBinding();
            CmbSubBuildTypeDataBinding(btid);
            CmbDcriterionTypeDataBinding();
            CmbSubDcriterionDataBinding(dtid);
        }
        private void CmbBuildTypeDataBinding()
        {
            dataSet = new DataSet();
            bllBuildType = new BLL.T_BuildTyppes();
            dataSet = bllBuildType.GetAllList();
            cmbBuildType.DataSource = dataSet.Tables[0];
            cmbBuildType.DisplayMember = dataSet.Tables[0].Columns["BTName"].ToString();
            cmbBuildType.ValueMember = dataSet.Tables[0].Columns["BTID"].ToString();
        }
        private void CmbSubBuildTypeDataBinding(int btid)
        {
            dataSet = new DataSet();
            bllSubBuildType = new BLL.T_SubBuildTyppes();
            dataSet = bllSubBuildType.GetList("btid=" + "'" + btid + "'");
            cmbSubBuild.DataSource = dataSet.Tables[0];
            cmbSubBuild.DisplayMember = dataSet.Tables[0].Columns["SBTName"].ToString();
            cmbSubBuild.ValueMember = dataSet.Tables[0].Columns["SBTID"].ToString();
        }
        private void CmbSubDcriterionDataBinding(int dtid)
        {
            dataSet = new DataSet();
            bllBuildDesignDcriterionSubType = new BLL.T_BuildDesignDcriterionSubTypes();
            dataSet = bllBuildDesignDcriterionSubType.GetList("DTID=" + "'" + dtid + "'");
            cmbSubDcriterion.DataSource = dataSet.Tables[0];
            cmbSubDcriterion.DisplayMember = dataSet.Tables[0].Columns["DSTName"].ToString();
            cmbSubDcriterion.ValueMember = dataSet.Tables[0].Columns["DSTID"].ToString();
        }
        private void CmbDcriterionTypeDataBinding()
        {
            dataSet = new DataSet();
            bllBuildDesignDcriterionType = new BLL.T_BuildDesignDcriterionTypes();
            dataSet = bllBuildDesignDcriterionType.GetAllList();
            cmbBuildDcriterion.DataSource = dataSet.Tables[0];
            cmbBuildDcriterion.DisplayMember = dataSet.Tables[0].Columns["DTName"].ToString();
            cmbBuildDcriterion.ValueMember = dataSet.Tables[0].Columns["DTID"].ToString();
        }

        private void cmbBuildType_SelectedIndexChanged(object sender, EventArgs e)
        {
            index++;
            if (index == 1 || index == 2)
            {
                System.Data.DataRowView drv = (DataRowView)cmbBuildType.SelectedValue;
                btid = Convert.ToInt32(drv.Row["BTID"]);
            }
            else
            {
                btid = Convert.ToInt32(cmbBuildType.SelectedValue);
                cmbSubBuild.DataSource = null;
                CmbSubBuildTypeDataBinding(btid);
            }
        }

        private void btnAddDefineAttribute_Click(object sender, EventArgs e)
        {
            this.sbtid = Convert.ToInt32(cmbSubBuild.SelectedValue);
            AddDefineAttributes addDefineAttribute = new AddDefineAttributes(sbtid, dtid, dstid);
            addDefineAttribute.Show();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("是否放弃新增具体规范？", "提示窗口", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dr == DialogResult.Yes)
            {
                this.FindForm().Close();
            }
        }

        private void cmbBuildDcriterion_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                dtid = Convert.ToInt32(cmbBuildDcriterion.SelectedValue);
                CmbSubDcriterionDataBinding(dtid);
            }
            catch (Exception ex)
            {
                DataRowView drv = (DataRowView)cmbBuildDcriterion.SelectedValue;
                dtid = Convert.ToInt32(drv.Row["DTID"]);
            }
        }

        private void cmbSubDcriterion_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                dstid = Convert.ToInt32(cmbSubDcriterion.SelectedValue);
            }
            catch (Exception ex)
            {
                DataRowView drv = (DataRowView)(cmbSubDcriterion.SelectedValue);
                dstid = Convert.ToInt32(drv.Row["DSTID"]);
            }
        }
    }
}